/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.i.kotionokyurievna.jewelry.domain.productmaterial;

import ua.i.kotionokyurievna.jewelry.domain.material.Material;
import ua.i.kotionokyurievna.jewelry.domain.product.Product;

/**
 *
 * @author Kateryna_Reznik
 */
public class ProductMaterial {
    private int productMaterialId;
    private Product product;
    private Material material;
    private double quantity;

    public ProductMaterial() {
    }

    public ProductMaterial(Product product, Material material, double quantity) {
        this.product = product;
        this.material = material;
        setQuantity(quantity);
    }

    public ProductMaterial(int productMaterialId, Product product, 
            Material material, double quantity) {
        this.productMaterialId = productMaterialId;
        this.product = product;
        this.material = material;
        setQuantity(quantity);
    }
    
    public ProductMaterial( ProductMaterial productMaterial ){
        if (productMaterial != null) {
            this.productMaterialId = productMaterial.productMaterialId;
            this.product = productMaterial.product;
            this.material = productMaterial.material;
            setQuantity(quantity);
        }
    }

    public int getProductMaterialId() {
        return productMaterialId;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public Material getMaterial() {
        return material;
    }

    public void setMaterial(Material material) {
        this.material = material;
    }

    public double getQuantity() {
        return quantity;
    }

    public void setQuantity(double quantity) {
        if ( quantity > 0 ){
            this.quantity = quantity;
        }
    }

    @Override
    public String toString() {
        return "ProductMaterial{" + "productMaterialId=" + productMaterialId + 
                ", product=" + product + ", material=" + material +
                ", quantity=" + quantity + '}';
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 53 * hash + (this.product != null ? this.product.hashCode() : 0);
        hash = 53 * hash + (this.material != null ? this.material.hashCode() : 0);
        hash = 53 * hash + (int) (Double.doubleToLongBits(this.quantity) ^ 
                (Double.doubleToLongBits(this.quantity) >>> 32));
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ProductMaterial other = (ProductMaterial) obj;
        if (this.product != other.product && (this.product == null || !this.product.equals(other.product))) {
            return false;
        }
        if (this.material != other.material && (this.material == null || !this.material.equals(other.material))) {
            return false;
        }
        if (Double.doubleToLongBits(this.quantity) != Double.doubleToLongBits(other.quantity)) {
            return false;
        }
        return true;
    }    
}
